local skel = fk.CreateSkill {
  name = "lb__jixing",
}

Fk:loadTranslationTable {
  ["lb__jixing"] = "济行",
  [":lb__jixing"] = "你本轮首次使用一种与「<b>慈心</b>」花色均不同的牌后，你摸一张牌。你可以将一张与「<b>慈心</b>」花色相同的基本牌当任意基本牌使用。",

  ["#lb__jixing"] = "济行：你可以将一张与「<b>慈心</b>」花色相同的基本牌当任意基本牌使用",

  ["@lb__jixing-round"] = "济行",

  ["$lb__jixing1"] = "我的药剂还很充足。",
  ["$lb__jixing2"] = "一场精妙的手术。",
}

skel:addEffect("viewas", {
  anim_type = "offensive",
  pattern = ".|.|.|.|.|basic",
  prompt = "#lb__jixing",
  interaction = function(self, player)
    local all_choices = Fk:getAllCardNames("b")
    local choices = player:getViewAsCardNames(skel.name, all_choices)
    if #choices > 0 then
      return UI.CardNameBox { choices = choices, all_choices = all_choices }
    end
  end,
  card_filter = function(self, player, to_select, selected, selected_targets)
    if #selected == 0 and self.interaction.data then
      local card = Fk:getCardById(to_select)
      if card.type == Card.TypeBasic then
        local suits = {}
        for _, id in ipairs(player:getPile("lb__cixin")) do
          table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        return table.contains(suits, card.suit) --and card.name ~= self.interaction.data
      end
    end
    return false
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or not self.interaction.data then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = skel.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = function(self, player)
    return #player:getPile("lb__cixin") > 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getPile("lb__cixin") > 0
  end,
})

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data.card.suit ~= Card.NoSuit then
      local suits = {}
      player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        if use.from == player and use ~= data then
          table.insertIfNeed(suits, use.card.suit)
        end
      end, Player.HistoryRound)
      for _, id in ipairs(player:getPile("lb__cixin")) do
        table.insertIfNeed(suits, Fk:getCardById(id).suit)
      end
      return not table.contains(suits, data.card.suit)
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, skel.name)
  end,
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true) and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:removeTableMark(player, "@lb__jixing-round", data.card:getSuitString(true))
  end,
})
--宝宝标记
skel:addEffect(fk.RoundStart, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name, true)
  end,
  on_refresh = function(self, event, target, player, data)
    skel:onAcquire(player, false)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  local suits = { "log_spade", "log_club", "log_heart", "log_diamond" }
  player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
    local use = e.data
    if use.from == player then
      table.removeOne(suits, use.card:getSuitString(true))
    end
  end, Player.HistoryRound)
  for _, id in ipairs(player:getPile("lb__cixin")) do
    table.removeOne(suits, Fk:getCardById(id):getSuitString(true))
  end
  if #suits > 0 then
    player.room:setPlayerMark(player, "@lb__jixing-round", suits)
  end
end)

return skel